#ifndef     __HANDLER_TASK_H
#define     __HANDLER_TASK_H

#include "../rtos/thread.h"
#include "../rtos/message_queue.h"
#include "../conn/message.h"

namespace task {

struct TaskInfo {
    uint8_t seq = 0;
    uint8_t cmd = 0;

    void reset() {
        seq = 0;
        cmd = 0;
    }
};

class HandlerTask : public rtos::Thread<HandlerTask, 2048, osPriorityHigh1> {

public:
    void init_start() {
        m_mq.init();
        this->start();
    }

    void run();

    const TaskInfo& task_info() const {
        return m_task_info;
    }

    void post(const conn::Message &msg) {
        m_mq.post(msg);
    }

private:
    void dispatch(const conn::Message &msg);

    rtos::MessageQueue<conn::Message, 5> m_mq;
    TaskInfo m_task_info;
};

extern HandlerTask handlerTask;

}



#endif
